<?php
class EmailFactory extends DeanFactory{

	private static $_instance;

	public static function getInstance() {
		if(is_null(self::$_instance)){
			self::$_instance = new EmailFactory();
		}
		return self::$_instance;
	}

	public function send($to, $object, $body)
	{
		$from = omcGet('smtp.sender.email');
		$fromName = omcGet('smtp.sender.name');
		$fromStr = $fromName." <".$from.">";

		if (!isset($to, $object, $body)) {
			$this->logger->warning('mail() => not all parameters provided.');
			throw new Exception('mail() => not all parameters provided.');
		}

		$headers    = array
		(
				'MIME-Version: 1.0',
				'Content-Type: text/html; charset="UTF-8";',
				'Content-Transfer-Encoding: 7bit',
				'Date: ' . date('r', $_SERVER['REQUEST_TIME']),
				'Message-ID: <' . $_SERVER['REQUEST_TIME'] . md5($_SERVER['REQUEST_TIME']) . '@' . $_SERVER['SERVER_NAME'] . '>',
				'From: ' . $fromStr,
				'Reply-To: ' . $fromStr,
				'Return-Path: ' . $fromStr,
				'X-Mailer: PHP v' . phpversion(),
				'X-Originating-IP: ' . $_SERVER['SERVER_ADDR'],
		);

		$this->logger->info("Sending email to $to from $fromStr : [$object] $body");
		return mail($to, '=?UTF-8?B?' . base64_encode($object) . '?=', $body, implode("\n", $headers));
	}


}